<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>成绩管理</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 20px;
      background-color: #f5f5f5;
    }
    .header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 20px;
      padding-bottom: 10px;
      border-bottom: 1px solid #ddd;
    }
    .welcome {
      font-size: 18px;
      color: #333;
    }
    .logout-btn {
      padding: 5px 15px;
      background-color: #dc3545;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      text-decoration: none;
    }
    .logout-btn:hover {
      background-color: #c82333;
    }
    .content {
      background-color: white;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }
    table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 20px;
    }
    th, td {
      border: 1px solid #ddd;
      padding: 12px;
      text-align: left;
    }
    th {
      background-color: #f2f2f2;
    }
    tr:nth-child(even) {
      background-color: #f9f9f9;
    }
    .back-btn {
      display: inline-block;
      padding: 8px 16px;
      background-color: #6c757d;
      color: white;
      text-decoration: none;
      border-radius: 4px;
      margin-bottom: 15px;
    }
    .back-btn:hover {
      background-color: #5a6268;
    }
    .user-info {
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .user-type {
      background-color: #6c757d;
      color: white;
      padding: 2px 8px;
      border-radius: 10px;
      font-size: 0.8rem;
    }
    .grade-excellent {
      color: #28a745;
      font-weight: bold;
    }
    .grade-good {
      color: #17a2b8;
      font-weight: bold;
    }
    .grade-average {
      color: #ffc107;
      font-weight: bold;
    }
    .grade-poor {
      color: #dc3545;
      font-weight: bold;
    }
  </style>
</head>
<body>
<div class="header">
  <h1>成绩管理</h1>
  <div class="user-info">
    <span class="welcome">欢迎, ${username}</span>
    <span class="user-type">${userType}</span>
    <a href="${pageContext.request.contextPath}/user/logout" class="logout-btn">退出登录</a>
  </div>
</div>

<div class="content">
  <a href="/student/students" class="back-btn">返回学生列表</a>

  <table>
    <thead>
    <tr>
      <th>课程名称</th>
      <th>学分</th>
      <th>授课教师</th>
      <th>成绩</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach var="grade" items="${grades}">
      <tr>
        <td>${grade.course.name}</td>
        <td>${grade.course.credit}</td>
        <td>${grade.course.teacher.name}</td>
        <td class="
                    <c:choose>
                        <c:when test="${grade.score >= 90}">grade-excellent</c:when>
                        <c:when test="${grade.score >= 80}">grade-good</c:when>
                        <c:when test="${grade.score >= 60}">grade-average</c:when>
                        <c:otherwise>grade-poor</c:otherwise>
                    </c:choose>
                ">
            ${grade.score}
        </td>
        <td>
          <a href="/student/update-grade?id=${grade.studentId}&course=${grade.courseId}">修改</a>
        </td>
      </tr>
    </c:forEach>
    </tbody>
  </table>
</div>
</body>
</html>
